/**
 * SqlMapConfigOverviewPage.java : [com.ibader.eclipse.editors.sqlmapconfig] Created on 2009. 5. 29.
 *
 * Copyright (c) 2009 Raccoon Project Team.
 * Seoul, Korea
 * All rights reserved.
 *
 */
package com.ibader.eclipse.editors.sqlmapconfig;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.widgets.Section;

import com.ibader.eclipse.Activator;
import com.ibader.eclipse.editors.pages.IBaderEditorPage;

/**
 * @author KimJungSu
 * @version
 */
public class SqlMapConfigOverviewPage extends IBaderEditorPage {

	private Combo trCombo = null;
	private Combo crCombo = null;
	private Combo dtCombo = null;

	private Button newButton = null;
	private Button addButton = null;
	private Button modButton = null;
	private Button delButton = null;

	private Section infoSection = null;
	private Section sqlmapSection = null;
	private TableViewer sqlmapTableViwer = null;


	public SqlMapConfigOverviewPage(FormEditor editor, String id, String title) {
		super(editor, id, title);
		// TODO Auto-generated constructor stub
		Activator.log("+++SqlMapConfigOverviewPage::Constructor");
		Activator.log("---SqlMapConfigOverviewPage::Constructor");
	}

	@Override
	public boolean canLeaveThePage() {
		// TODO Auto-generated method stub
		return super.canLeaveThePage();
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub
		Activator.log("+++SqlMapConfigOverviewPage::dispose");
		super.dispose();

		Activator.log("+++SqlMapConfigOverviewPage::dispose");
	}

	@Override
	public void doSave(IProgressMonitor monitor) {
		// TODO Auto-generated method stub
		Activator.log("+++SqlMapConfigOverviewPage::doSave");
		super.doSave(monitor);

		Activator.log("---SqlMapConfigOverviewPage::doSave");
	}

	@Override
	public void doSaveAs() {
		// TODO Auto-generated method stub
		Activator.log("+++SqlMapConfigOverviewPage::doSaveAs");
		super.doSaveAs();

		Activator.log("---SqlMapConfigOverviewPage::doSaveAs");
	}

	@Override
	public void init(IEditorSite site, IEditorInput input) {
		// TODO Auto-generated method stub
		Activator.log("+++SqlMapConfigOverviewPage::init");
		super.init(site, input);

		Activator.log("---SqlMapConfigOverviewPage::init");
	}

	@Override
	public boolean isActive() {
		// TODO Auto-generated method stub
		return super.isActive();
	}

	@Override
	public boolean isDirty() {
		// TODO Auto-generated method stub
		return super.isDirty();
	}

	@Override
	public boolean isEditor() {
		// TODO Auto-generated method stub
		return super.isEditor();
	}

	@Override
	public boolean isSaveAsAllowed() {
		// TODO Auto-generated method stub
		return super.isSaveAsAllowed();
	}

	@Override
	public void setActive(boolean active) {
		// TODO Auto-generated method stub
		super.setActive(active);
	}

	@Override
	public void setFocus() {
		// TODO Auto-generated method stub
		super.setFocus();
	}

	@Override
	public void setIndex(int index) {
		// TODO Auto-generated method stub
		super.setIndex(index);
	}

	@Override
	protected void createFormContent(IManagedForm managedForm) {
		// TODO Auto-generated method stub
		Activator.log("+++SqlMapConfigOverviewPage::createFormContent");
		super.createFormContent(managedForm);

		// set form properties
		form.setExpandHorizontal(true);
		form.setExpandVertical(true);
		form.setText("Overview");
		form.getBody().setLayout(new FillLayout(SWT.VERTICAL));

		Composite composite = toolkit.createComposite(form.getBody());
		//toolkit.setBorderStyle(SWT.BORDER);
		toolkit.paintBordersFor(composite);
		GridLayout layout = new GridLayout();
		layout.numColumns = 2;
		composite.setLayout(layout);
		composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

		// create information content
		createInformationContent(composite);

		// create sqlmap content
		createSqlMapContent(composite);

		// initialize contents
		initContents();

		// add event handler for contents
		addContentEventListener();

		Activator.log("---SqlMapConfigOverviewPage::createFormContent");
	}

	protected void addContentEventListener() {
		// TODO Auto-generated method stub
		Activator.log("+++SqlMapConfigOverviewPage::addContentEventListener");
		Activator.log("---SqlMapConfigOverviewPage::addContentEventListener");
	}

	protected void initContents() {
		// TODO Auto-generated method stub
		Activator.log("+++SqlMapConfigOverviewPage::initContents");
		Activator.log("---SqlMapConfigOverviewPage::initContents");
	}

	private void createSqlMapContent(Composite parent) {
		// TODO Auto-generated method stub
		Activator.log("+++SqlMapConfigOverviewPage::createSqlMapContent");

		// create section for information
		sqlmapSection = toolkit.createSection(parent,
			Section.DESCRIPTION | Section.TITLE_BAR | Section.EXPANDED);
		sqlmapSection.marginWidth = 10;
		sqlmapSection.setText("SqlMap");
		sqlmapSection.setDescription("sqlmap's description");

		GridData gd = new GridData(GridData.FILL);
		sqlmapSection.setLayoutData(gd);
		sqlmapSection.setLayout(new FillLayout());

		// create controls for composite
		Composite composite = toolkit.createComposite(sqlmapSection);
		GridLayout layout = new GridLayout();
		layout.numColumns = 2;
		composite.setLayout(layout);

		// set client for sqlmap section
		sqlmapSection.setClient(composite);

		// create control and set data
		gd = new GridData(GridData.FILL_HORIZONTAL);
		gd.horizontalSpan = 2;

		final Label proLabel = new Label(composite, SWT.FILL);
		proLabel.setText("Properties:");
		proLabel.setLayoutData(gd);

		final Table table = new Table(composite, SWT.BORDER
				| SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
		gd = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_BOTH);
		table.setLayoutData(gd);
		table.setLinesVisible(true);
		table.setHeaderVisible(true);

		String[] titles = {"Name", "Value"};
		int[] titles_size = { 80, 120 };
		TableColumn[] columns = new TableColumn[titles.length];
		for (int i = 0; i < titles.length; i++) {
			columns[i] = new TableColumn(table, SWT.NONE);
			columns[i].setText(titles[i]);
			columns[i].setWidth(titles_size[i]);
		}

		sqlmapTableViwer = new TableViewer(table);

		// create buttons composite
		Composite buttonComposite = new Composite(composite, SWT.FILL);
		buttonComposite.setLayout(new GridLayout());
		buttonComposite.setLayoutData(gd);

		gd = new GridData(GridData.FILL_HORIZONTAL);

		newButton = new Button(buttonComposite, SWT.NONE);
		newButton.setText("New");
		newButton.setLayoutData(gd);

		addButton = new Button(buttonComposite, SWT.NONE);
		addButton.setText("Add");
		addButton.setLayoutData(gd);

		modButton = new Button(buttonComposite, SWT.NONE);
		modButton.setText("Modify");
		modButton.setLayoutData(gd);

		delButton = new Button(buttonComposite, SWT.NONE);
		delButton.setText("Delete");
		delButton.setLayoutData(gd);

		Activator.log("---SqlMapConfigOverviewPage::createSqlMapContent");
	}

	private void createInformationContent(Composite parent) {
		// TODO Auto-generated method stub
		Activator.log("+++SqlMapConfigOverviewPage::createInformationContent");

		// create section for information
		infoSection = toolkit.createSection(parent,
			Section.DESCRIPTION | Section.TITLE_BAR | Section.EXPANDED);
		infoSection.marginWidth = 10;
		infoSection.setText("Information");
		infoSection.setDescription("information's description");

		GridData gd = new GridData(GridData.FILL);
		infoSection.setLayoutData(gd);
		infoSection.setLayout(new FillLayout());

		// create controls for composite
		Composite composite = toolkit.createComposite(infoSection);
		GridLayout layout = new GridLayout();
		layout.numColumns = 2;
//		layout.makeColumnsEqualWidth = false;
		composite.setLayout(layout);

		// set client for information
		infoSection.setClient(composite);

		// create control and set data
		gd = new GridData(GridData.BEGINNING);

		final Label trLabel = new Label(composite, SWT.NONE);
		trLabel.setText("Transaction Manager:");
		trLabel.setLayoutData(gd);

		gd = new GridData(GridData.FILL_HORIZONTAL);
		trCombo = new Combo(composite, SWT.DROP_DOWN);
		trCombo.setLayoutData(gd);

		gd = new GridData(GridData.BEGINNING);
		final Label crLabel = new Label(composite, SWT.NONE);
		crLabel.setText("Class Required:");
		crLabel.setLayoutData(gd);

		gd = new GridData(GridData.FILL_HORIZONTAL);
		crCombo = new Combo(composite, SWT.DROP_DOWN);
		crCombo.setLayoutData(gd);

		gd = new GridData(GridData.BEGINNING);
		final Label dtLabel = new Label(composite, SWT.NONE);
		dtLabel.setText("DataSource Type:");
		dtLabel.setLayoutData(gd);

		gd = new GridData(GridData.FILL_HORIZONTAL);
		dtCombo = new Combo(composite, SWT.DROP_DOWN);
		dtCombo.setLayoutData(gd);

		Activator.log("---SqlMapConfigOverviewPage::createInformationContent");
	}

	@Override
	public void propertyChange(PropertyChangeEvent event) {
		// TODO Auto-generated method stub

	}

}
